home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7238 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mudskipper.cac.psu.edu!user
  2. From: fcusack@tdx.org (frank.)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: && operator question
  5. Date: Thu, 15 Feb 1996 18:17:50 -0400
  6. Organization: Psychic Enemies Network
  7. Message-ID: <fcusack-1502961817500001@mudskipper.cac.psu.edu>
  8. References: <4fu69a$b7e@sphinx.Gsu.EDU> <4fuet4$b3r@niktow.canisius.edu> <31232EC0.3CD@visigenic.com>
  9. NNTP-Posting-Host: mudskipper.cac.psu.edu
  10.  
  11. In article <31232EC0.3CD@visigenic.com>, Tim O'Neil <toneil@visigenic.com>
  12. wrote:
  13.  
  14. > Alan Duchan wrote:
  15. > > An ANSI conforming compiler will not evaluate expression2 when expression1
  16. > > is false.  Similarly, for
  17. > >       expr1 || expr2
  18. > > 
  19. > > when expr1 is true, expr2 will not be evaluated.
  20. > Whoops. I guess my solution isn't the way to write the 
  21. > evaluation (unless you want that effect.) What would be
  22. > the effect of writing it:
  23. > ((exp1) || (exp2)) stamt;?
  24.  
  25. You would have a syntax error b/c you left out the "if". Had you included
  26. the if, if exp1 evaluates to true, then exp2 is *not* evaluated (and any
  27. side effects from exp2 thus do not occur) and stamt is executed. If exp1
  28. evaluates to false, then exp2 is evaluated and if it is true, stamt is
  29. executed.
  30.  
  31. So if exp2 were something like i++ then it does not get executed if exp1
  32. is true, and *i does not get incremented*.
  33. ~Frank
  34.  -- I am Pentium of Borg.  Division is futile.  You will be approximated. --
  35.  --   If you build it, they will come --> http://www.tdx.org/~fcusack/    --
  36.  -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F  3F 64 80 65 8B 0F F9 EA --
  37.